import { get, post, fanyiPost } from "./request";
import { MD5 } from "./md5";

let apiFun = {} as any;
const apiHeader = "https://api.pencil-stub.com"
apiFun.postLogin = (p: any) =>
    post("webApi/v1/users/my_address/address_edit_before", p, '');
// apiFun.getPhone = p => post("webApi/visitor/example/json.do", p);
// apiFun.getCode = (p: any)=> post("/webApi/user/login/get-code", p);
// apiFun.login = (p: any)=> post("/webApi/user/login", p);
apiFun.getUserInfo = (p: any) => post(apiHeader + "/user/info", p, "");//获取个人信息
apiFun.thirdPay = (p: any) => get(apiHeader + "/user/third/pay/order/apply/web", p);//第三方支付申请
apiFun.thirdQuery = (p: any) => get(apiHeader + "/user/query/pay/apply/web", p);//第三方支付结果查询



//Ai绘画接口默认参数
let paintData = {
    detect: true,
    spec: {
        prompt: '',
        negative_prompt: "",
        model: '',
        // controlnet_units: [{ input_image: '', weight: 1 }],
        hd: { scale: 1, strength: 0.5 },//越大越不相似
        width: 512,
        height: 512,
        batch_size: 1,
        steps: 20,
        cfg_scale: 7,
        style_name: "",
        sampling: "",
        lora: "",
        seed: 1122334456
    }
}
apiFun.aiPaint = (p: any) => post(apiHeader + "/ai/ai_paint/img_generate", { pegg: p.batch_size * 40, detect: true, spec: { ...paintData.spec, ...p } }, "");//ai绘画
apiFun.allTask = (p: any) => post(apiHeader + "/ai/mini_story/all_task", p, ""); //所根据uid查询所有任务列表
apiFun.Model2 = (p: any) => post(apiHeader + "/data/ai_paint/models/v2", p, ""); //获取Ai绘画模型（新）
//剧本任务相关
apiFun.ScriptProgress = (p: any) => get(apiHeader + "/ai/mini_story/get_task_progress", p); //剧本进度
apiFun.delImgsInOss = (p: any) => post(apiHeader + "/data/ai_paint/del", p, ""); //删除图片
apiFun.upTaskStatus = (p: any) => post(apiHeader + "/ai/mini_story/update_task", p, ""); //更新任务状态
apiFun.ScriptTaskInfo = (p: any) => post(apiHeader + "/ai/mini_story/task_info", p, ""); //剧本信息
apiFun.addScriptTask = (p: any) => post(apiHeader + "/ai/mini_story/add_task", p, ""); //添加剧本任务
apiFun.optimize = (p: any) => post(apiHeader + "/ai/ai_paint/ai_prompt_single", p, ""); //优化提示词
apiFun.hdImg = (p: any) => post(apiHeader + "/ai/ai_paint/hd", p, ""); //对图片高清处理

//我的账户相关
apiFun.peggRechargeList = (p: any) => post(apiHeader + "/user/pegg_recharge/list", p, ""); //获取可选的皮蛋充值列表
apiFun.FanyiPP = (p: any) => post("/fanyi-pp-api/translate/to", p, ""); //皮皮翻译
//测试方法
apiFun.test = (p: any) => get(apiHeader + "/fanyi-api/testApi/imgs/get_list", p);//测试请求


apiFun.Fanyi = (p: any) => {
    const APPID = "20230728001760908";
    const KEY = "1OG6tQxvWwBFRM4BGiQp";
    const salt = new Date().getTime();
    const str = APPID + p.q + salt + KEY;
    // 执行MD5编码
    const sign = MD5(str);
    let req = {
        q: p.q, // 需要翻译的内容
        from: "auto",
        to: p.to, // 中文: "zh" ； 英文: "en"
        appid: APPID,
        salt: salt,
        sign: sign,
    };
    return fanyiPost("/fanyi-api/api/trans/vip/translate", req, {
        headers: { "Content-Type": "application/x-www-form-urlencoded" },
    });
};

export default apiFun;
